{layout name="common/layout" /}
<style>
	label{
		width:700px;
		height: 31px;
		display: block;
		margin:10px 0px 10px 20px;
	}
	label span {
		width:120px;
		height:30px;
		display: block;
		float: left;
		text-align: end;
		padding-top: 25px;
		float:left;
	}
	.size-M{
		float:left;
	}
</style>
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a></div>
<div class="Hui-article-box" style="margin-top: 37px;">
	<div class="breadcrumb"><i class="Hui-iconfont"></i> <a href="{:url('home/index')}" class="maincolor">首页</a>
		<span class="c-999 en">&gt;</span>
	</div>
	<div class="Hui-article">
			<div class="article-order" style="width: 1008px;margin:20px auto;box-sizing: border-box;">
				<div id="tab_demo">
				    <div class="tabBar clearfix" style="border-bottom: 1px solid #ccc;padding-bottom: 20px;">
				    	<span style="width: 443px;">基本资料</span><span style="width: 443px;">店铺信息</span>
					</div>
						<div class="tabCon">
							<form id="frm" style="border:0;"> 	
							<label for=""  style="margin-left: 20px;">
								<span>&nbsp;&nbsp;&nbsp;&nbsp;手机号码：</span>
								<input id="phone" type="text" class="input-text radius size-M" value="{$data['merchant_tel']}"   disabled="true">
							</label><br>
							<label for="" style="margin-left: 20px;">
								<span>图片验证码：</span>
								<input type="text" name="captcha"  class="input-text radius size-M" id="captchaCode" placeholder="输入验证码" autocomplete="off">
								<div id="captchas" style="float:left;width:120px;margin:20px 0px 10px 10px;">
									<img id="capt" src="{:url('index/captcha')}" width="120" height="30" >
								</div>
							</label><br>
							<label for="" style="margin-left: 20px;">
								<span>手机验证码：</span>
								<input id="verify_code" type="text" class="input-text radius size-M" placeholder="请输入手机验证码">
								<input id="btnSendCode" type="button" class="btn" value="获取验证码" onClick="sendMessage()" style="width:120px;text-align: center;"/>
							</label><br>
							<label for=""  style="margin-left: 20px;">
								<span>&nbsp;&nbsp;&nbsp;&nbsp;修改密码：</span>
								<input type="password" id="new_password" class="input-text radius size-M" placeholder="密码长度6-20位">
							</label>
							<div class="btn-l">
								<input type="button" onclick="updatePwd();" class="btn" value="保存">
								<!-- <input type="button" class="btn" onclick="window.history.go(-1);" value="返回" style="margin-left: 20px;"> -->
							</div>
							</form>	
						</div>	
					<div class="tabCon">
						<form id="frm" action="" style="border:0;">
						<input type="hidden" name="store_id" value="{$store['store_id']}" />
						<label for="" style="margin-left: 20px;">
							<span>&nbsp;&nbsp;&nbsp;&nbsp;店铺名称：</span>
							<input type="text" name="store_name" value="{$store['store_name']}" class="input-text radius size-M"  disabled="true">
						</label><br>
						<label for="" style="margin-left: 20px;">
							<span>&nbsp;&nbsp;&nbsp;&nbsp;客服电话：</span>
							<input type="text" name="cs_phone" value="{$store['store_cs_phone']}" class="input-text radius size-M"  />
						</label><br>
						<label for="" style="margin-left: 0px;">
							<div style="float: left;margin-left: 20px;">
								<span>&nbsp;&nbsp;&nbsp;&nbsp;店铺介绍：</span>
							</div><textarea name="store_introduce" id="" cols="47" rows="10" style="margin-left: 30px;">{$store['store_introduce']}</textarea>
						</label><br>
						<label for="" class="cl" style="margin-left: 40px;">
							<div style="float: left;margin-top: 130px;margin-left: 20px;">&nbsp;&nbsp;店铺背景图：</div>
	                		<div style="width: 200px;float: left;margin-left: 24px;margin-top: 100px;">
								<input type="hidden" value="{$store['store_bg_img']}" id="store_bg_img" name="store_bg_img">								
								<img width="150px" height="150px" onclick="$('#mainPic3').click()" src="STORE_IMG_PATH/bg/{$store['store_bg_img']}"/><br>
								<input  type="file" id="mainPic3" onchange="upload_bg_img('mainPic3');" name="imagefile" style="margin:10px 0 20px 0px;display:none;"/><br>
								<input  type="button" class="btn btn1" onclick="upload_bg_img('mainPic3');"  value="上传" style="margin:10px 0 20px 0px;display:none;"/>							
							</div>
						</label><br>
						<label for="" class="cl" style="margin-left: 0px;padding-top: 200px;">
							<div style="float: left;margin-top: 10px;margin-left: 20px;"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;店铺头像：</span></div>
		                	<div style="width: 200px;float: left;margin-left: 24px;margin-top: 20px;">
								<input type="hidden" value="{$store['store_face_img']}" id="store_face_img" name="store_face_img">								
								<img width="150px" height="150px" onclick="$('#mainPic2').click()" src="STORE_IMG_PATH/face/{$store['store_face_img']}"/><br>
								<input  type="file" id="mainPic2" onchange="upload_face_img('mainPic2');" name="imagefile" style="margin:10px 0 20px 0px;display:none;"/><br>
								<input  type="button" class="btn1 btn" onclick="upload_face_img('mainPic2');"  value="上传" style="margin:10px 0 20px 0px;display:none;"/>								
							</div>
						</label><br>
						<label for="" style="margin-left: 20px;padding-top: 150px;">
							<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;店铺类型：</span>
							<input type="text" disabled="true" class="input-text radius size-M" value="企业店">
						</label>
						<div class="btn-l" style="margin-left: 35px;padding-top: 20px;">
							<input type="button" style="margin-left: 500px;" class="btn" onclick="saveStore({$store['store_id']});" value="保存">
						</div>
						</form>	
					</div>
				</div>		
			</div>
		</form>	
	</div>
</div>
	
<script type="text/javascript">
	$('#capt').click(function () {
		$('#capt').attr('src', "{:url('index/captcha', '', false)}/#" + Math.random());
	});

function saveStore(storeId)
{
	var store_id = $('input[name=store_id]').val();
	var store_face_img = $('input[name=store_face_img]').val();
	var store_bg_img = $('input[name=store_bg_img]').val();
	var store_introduce = $('textarea[name=store_introduce]').val();
	var cs_phone = $('input[name=cs_phone]').val();
	$.ajax({
        type: "POST", 
        url: "{:url('merchant/update2', '', false)}",
        data : {'store_id':store_id,'store_face_img':store_face_img,'store_bg_img':store_bg_img,'store_introduce':store_introduce,'cs_phone':cs_phone},
        dataType: "json",
        success: function (data){ 
        	layer.msg(data.msg);
        }
    });
}

var InterValObj; //timer变量，控制时间
var count = 60; //间隔函数，1秒执行
var curCount;//当前剩余秒数
var code = ""; //验证码
var codeLength = 6;//验证码长度
function sendMessage() {
	var phone = $("#phone").val();
	var captcha = $("input[name='captcha']").val();
	if (!captcha) {
		layer.msg('请输入图片验证码');
	} else {
		curCount = count;

		$.ajax({
			type: "post",
			dataType: "json",
			url: "{:url('index/sendMessage', '', false)}",
			data:{'phone':phone,'captcha':captcha},
			error: function (XMLHttpRequest, textStatus, errorThrown) {},
			success: function (data) {
				if (data.status == 0) {
					InterValObj = window.setInterval(SetRemainTime, 1000);
					$("#btnSendCode").attr("disabled", "true");
					$("#btnSendCode").val(+curCount + "秒后再获取");
					layer.msg(data.msg);
				}
				if (data.status == 1) {
					InterValObj = window.setInterval(SetRemainTime, 1000);
					$("#btnSendCode").attr("disabled", "true");
					$("#btnSendCode").val(+curCount + "秒后再获取");
				}
				if (data.status == 2){
					layer.msg(data.msg);
				}
			}
		});
	}
}
//timer处理函数
function SetRemainTime() {
    if (curCount == 0) {                
        window.clearInterval(InterValObj);//停止计时器
        $("#btnSendCode").removeAttr("disabled");//启用按钮
        $("#btnSendCode").val("重新发送验证码");
        code = ""; //清除验证码。如果不清除，过时间后，输入收到的验证码依然有效    
    }
    else {
        curCount--;
        $("#btnSendCode").val( + curCount + "秒再获取");
    }
}
</script>
<script>
	$(function(){
		$.Huitab("#tab_demo .tabBar span","#tab_demo .tabCon","current","click","0")
	});

	var GG = {
        "kk":function(mm) {
           var ym=mm;
        }
    }
	$("#page").initPage(71,1,GG.kk);
	$("#page1").initPage(71,1,GG.kk);
	$("#page2").initPage(71,1,GG.kk);
	$("#page3").initPage(71,1,GG.kk);
	$("#page4").initPage(71,1,GG.kk);

	function upload_bg_img( img_id )
	{	
		var formData = new FormData();
		formData.append("file",$("#"+img_id+"")[0].files[0]);
		$.ajax({
			type:"post",
			url:"{:url('store/upload_bg_img', '', false)}",
			async:true,
			cache: false,
		    data: formData,
		    processData: false,
		    contentType: false,
			data : formData,
			success : function(res){
		    	$("#"+img_id+"").siblings("img").attr("src",res.data.access_url);
		    	$("#"+img_id+"").siblings("img").siblings("input[type=hidden]").val(res.data.filename);
			},
			error : function(res){
				console.log(res.access_url);
			}
		});
	}
	
	function upload_face_img( img_id )
	{	
		var formData = new FormData();
		formData.append("file",$("#"+img_id+"")[0].files[0]);
		$.ajax({
			type:"post",
			url:"{:url('store/upload_face_img', '', false)}",
			async:true,
			cache: false,
		    data: formData,
		    processData: false,
		    contentType: false,
			data : formData,
			success : function(res){
		    	$("#"+img_id+"").siblings("img").attr("src",res.data.access_url);
		    	$("#"+img_id+"").siblings("img").siblings("input[type=hidden]").val(res.data.filename);
			},
			error : function(res){
				console.log(res.access_url);
			}
		});
	}
	
	function updatePwd()
	{
    	var tel = $('#phone').val();
    	var pw = $('#new_password').val();
    	var code = $('#verify_code').val();
        
		if (code == '') {	 
			layer.msg("验证码不能为空");
			$("#verify_code").focus();
			return ;
		} 
		
		if (pw == '') {	 
			layer.msg("密码不能为空");
			$("#new_password").focus();
			return ;
		}

		if (pw.length < 8) {	 
			layer.msg("密码不能少于8位");
			$("#new_password").focus();
			return ;
		}		
			
    	$.ajax({
			type: "POST",
			url: "<?php echo url('index/updatePwd', '', false); ?>",
			dataType: 'json',
			cache: false,
			data: {tel:tel,pw:pw,code:code},
			success: function(data) {
				layer.msg(data.msg);
				window.location.reload();
			},
			error: function(xhr, status, error) {
				
			}
        }); 
	}	   
</script>
 